package com.lixn.homework.controller;

import com.lixn.homework.pojo.Resume;
import com.lixn.homework.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/resume")
public class MyController {

    @Autowired
    private ResumeService resumeService;



    @RequestMapping("/list")
    public String resumeList(Model model) throws Exception{
        List<Resume> resumes = resumeService.queryAll();
        System.out.println("resumeList<<<<"+resumes);
        model.addAttribute("resumeList", resumes);
        return "list";
    }


    @RequestMapping("/login")
    public String login(HttpSession session, String username, String password, Model model) throws Exception{
        if("admin".equals(username) && "admin".equals(password)){
            session.setAttribute("admin", "admin");
            return "redirect:/resume/list";
        }
        model.addAttribute("msg", "用户名/密码错误，请重新输入");
        return "login";
    }

    @RequestMapping("/tologin")
    public String toLogin(HttpSession session) throws Exception{
        return "login";
    }
}
